home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / ptv2n1.arc / FILE.HPP < prev    next >
Text File  |  1991-03-26  |  554b  |  25 lines

  1.  
  2. // FILE.HPP : encapsulation of FILE* for ease and safety
  3. #ifndef FILE_HPP_
  4. #define FILE_HPP_
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. class fileptr {
  9.   FILE* filep;
  10. public:
  11.   fileptr(char * name, char * mode = "r") {
  12.     filep = fopen(name, mode);
  13.     if(!filep) {
  14.       fprintf(stderr, "cannot open %s\n", name);
  15.       exit(1);
  16.     }
  17.   }
  18.   ~fileptr() { fclose(filep); }
  19.   // automatic type conversion operator, so you can 
  20.   // use a fileptr everywhere you use a FILE*:
  21.   operator FILE*() { return filep; }
  22. };
  23.  
  24. #endif FILE_HPP_
  25.